package com.tz.zczc.dao.api.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tz.zczc.dao.api.KeywordsDao;
import com.tz.zczc.dao.mapper.KeywordsMapper;
import com.tz.zczc.domain.model.entity.Keywords;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * @Author:Mark
 * @Description:
 * @Date: Created on 15:23 2018-12-5
 * @Modify by:
 */
@Repository
public class KeywordsDaoImpl implements KeywordsDao {

  @Autowired
  private KeywordsMapper keywordsMapper;

  @Override
  public Integer addRecordSelective(Keywords keywords) {
    int i = keywordsMapper.insertSelective(keywords);
    return i;
  }

  @Override
  public List<Keywords> selectBYKeywords(Keywords keywords) {
    List<Keywords> result = keywordsMapper.select(keywords);
    return result;
  }

  @Override
  public PageInfo<Keywords> selectKeywordsByPages(Integer pageSize,
      Integer pageNum) {
    PageHelper.startPage(pageNum,pageSize);
    Example example=new Example(Keywords.class);
    Criteria criteria = example.createCriteria();
    Keywords keywords=new Keywords();
    keywords.setDeleted(false);
    criteria.andEqualTo("deleted",keywords);
    return new PageInfo<>(keywordsMapper.selectByExample(example));
  }

  @Override
  public Integer updateRecordSelective(Keywords keywords) {
    return keywordsMapper.updateByPrimaryKeySelective(keywords);
  }

  @Override
  public Integer deleteById(List<String> ids) {

    Example example=new Example(Keywords.class);
    Criteria criteria = example.createCriteria();
    criteria.andIn("id",ids);
   /* keywordsMapper.up
    keywordsMapper.updateByExample(new Keywords(),example);*/
    return keywordsMapper.deleteByExample(example);
  }

  @Override
  public Integer logicDeleteById(List<String> ids,Keywords keywords) {
    Example example=new Example(Keywords.class);
    Criteria criteria = example.createCriteria();
    criteria.andIn("id",ids);
    return keywordsMapper.updateByExampleSelective(keywords,example);
  }

}
